<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Setting extends Model
{
    public $timestamps = false;

    const POINTS_SET = 'points_set';
    const TOUCH_SET = 'touch_set';

    protected $Commission = [                   //量碰提成率
        'level_Rate'=>[
            ['level_id'=>1,'rate'=>'0.08'],
            ['level_id'=>2,'rate'=>'0.09'],
            ['level_id'=>3,'rate'=>'0.10'],
            ['level_id'=>4,'rate'=>'0.11']
        ]
    ];

    protected $pointsSet = [
        'point_bonus' => 30,   // 每点奖励金额
        'level_info' => [ // 卡等级，建点层数，建点数量，预计最大奖金
            ['level_id' => 1, 'level_num' => 6, 'level_points' => 126, 'level_bonus' => 3780],
            ['level_id' => 2, 'level_num' => 8, 'level_points' => 512, 'level_bonus' => 15360],
            ['level_id' => 3, 'level_num' => 10, 'level_points' => 2048, 'level_bonus' => 61440],
            ['level_id' => 4, 'level_num' => 12, 'level_points' => 8192, 'level_bonus' => 245760]
        ]
    ];

    protected $touchSet = [
        'touch_pv' => 0.7,        // pv值
        'touch_layers_rules' => [ // 量碰层数规则
            ['rec_num' => 2, 'touch_layers' => 2],  // 直推人数，可量碰层数
            ['rec_num' => 3, 'touch_layers' => 3],
            ['rec_num' => 4, 'touch_layers' => 4],
            ['rec_num' => 5, 'touch_layers' => 5],
            ['rec_num' => 6, 'touch_layers' => 99999]
        ],
        'touch_bonus_rules' => [ // 量碰提成比例规则
            // 卡等级，量碰基数，提成比例，超过基数提成比例
            ['level_id' => 1, 'touch_base' => 3000, 'bonus_rate' => 30, 'extra_bonus_rate' => 6],
            ['level_id' => 2, 'touch_base' => 6000, 'bonus_rate' => 30, 'extra_bonus_rate' => 8],
            ['level_id' => 3, 'touch_base' => 12000, 'bonus_rate' => 30, 'extra_bonus_rate' => 10],
            ['level_id' => 4, 'touch_base' => 24000, 'bonus_rate' => 30, 'extra_bonus_rate' => 12]
        ]
    ];

    protected $moneyToScoresRate = 1;

    /**
     * 获取建点规则配置
     * @return array
     */
    public function getPointsSet() : array
    {
        return $this->pointsSet;
    }

    /**
     * 获取量碰规则配置
     * @return array
     */
    public function getTouchSet() : array
    {
        return $this->touchSet;
    }

    public function getCommissionRate($level)
    {
        $data = $this->Commission;

        foreach($data['level_Rate'] as $d){
            if($d['level_id']==$level){
                return $d['rate'];
            }
        }
    }
    /**
     * 获取人民币兑积分比例
     * @return int
     */
    public function getMoneyToScoresSet()
    {
        return $this->moneyToScoresRate;
    }

    public function calculatePointsByLevels(int $levels) : int
    {
        $result = 0;
        for ($i = 1; $i <= $levels; ++$i) {
            $result += pow(2, $i);
        }
        return $result;
    }
}
